package gui.requestDetail;

import java.util.List;
import java.util.Vector;

import javax.swing.JTable;
import javax.swing.ListSelectionModel;
import javax.swing.SwingConstants;
import javax.swing.table.AbstractTableModel;
import javax.swing.table.DefaultTableCellRenderer;
import javax.swing.table.TableModel;
import javax.swing.table.TableRowSorter;



import model.search.Order;

public class MyTableModel extends AbstractTableModel{

//	private List<Request> listReq;
	Vector<Data> v = new Vector<Data>(10,10);


	
		
	public String[] m_colNames = { "Id Order","Instructors"};
    public Class[] m_colTypes = { Integer.class, String.class};
	
    
    public MyTableModel(List<Order> list, JTable jTable1) {
	    super();
	    getListData(v,list);
	    jTable1.setRowSorter(new TableRowSorter<TableModel>(this));
	    jTable1.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
	    jTable1.setRowSelectionAllowed(true);
	    jTable1.setUpdateSelectionOnSort(true);
	    jTable1.setShowGrid(false);
	    ((DefaultTableCellRenderer)jTable1.getDefaultRenderer(Integer.class)).setHorizontalAlignment(SwingConstants.CENTER);
	    ((DefaultTableCellRenderer)jTable1.getDefaultRenderer(String.class)).setHorizontalAlignment(SwingConstants.CENTER);
	    }
    
    public void getListData(Vector<Data> v,List<Order> list){
    	for (int i = 0; i < list.size(); i++) {
    		v.addElement(new Data(list.get(i)));
    	}
    }

    
    public String getColumnName(int col) {
    	return m_colNames[col];
    }
    public Class getColumnClass(int col) {
    	return m_colTypes[col];
    }
    
	public int getColumnCount() {
		return m_colNames.length;
	}
	public int getRowCount() {
		return v.size();
	}
	
	public void setValueAt(Object value, int row, int col) {
	      Data macData = (Data) (v.elementAt(row));

	      switch (col) {
	      case 0:
	        macData.setA((Integer) value);
	        break;
	      case 1:
	        macData.setB((String) value);
	        break;
	      case 2:
	    	  macData.setR((Order) value);
	    	  break;
	      }
	    }
    
	public Object getValueAt(int row, int col) {
	      Data macData = (Data) (v.elementAt(row));

	      switch (col) {
	      case 0:
	        return macData.getA();
	      case 1:
	        return macData.getB();
	      case 2:
	    	  return macData.getR();
	    	  
	      }
	      return new String();
	    }
	public Object getValueAt1(int row, int col) {
		Data macData = (Data) (v.elementAt(row));
		
		switch (col) {
		case 0:
			return macData.getA();
		case 1:
			return macData.getB();
		case 2:
			return macData.getR();
			
		}
		return new String();
	}

	
	
	class Data {
		  private Integer a;

		  private String b;

		  private Order r;
		  
		  public Data(Order order) {
			  this.r=order;
			  this.a=order.getIdOrder();
			  this.b=order.getAnInstructor().getName();
		}

		public Integer getA() {
		    return a;
		  }

		  public String getB() {
		    return b;
		  }
		  public Order getR(){
			  return r;
		  }
		  
		  

		  public void setA(Integer aa) {
		    a = aa;
		  }

		  public void setB(String macName) {
		    b = macName;
		  }
		  public void setR(Order macName) {
			  r = macName;
		  }

		}

	
	
}
